package com.im.partchat.widget.dialog;


import android.app.AlertDialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.im.partchat.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ldy on 2016/11/23.
 */

public class QRCodeDialog {
    protected final AlertDialog.Builder builder;
    protected final Context context;
    protected ViewGroup rootView;
    protected AlertDialog dialog;
    protected float density;
    @BindView(R.id.tv_dialog_qrcode_code)
    TextView textView;
    @BindView(R.id.iv_dialog_qrcode)
    ImageView imageView;


    public QRCodeDialog(Context context) {
        this.context = context;
        builder = new AlertDialog.Builder(context);
        initView();
        builder.setView(rootView);
    }

    private void initView() {
        rootView = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.dialog_qrcode, null);
        ButterKnife.bind(this, rootView);
        builder.setView(rootView);
    }

    public void setQrCodeName(String name) {
        if (!TextUtils.isEmpty(name))
            textView.setText(name);
    }

    public void setQrCodeUrl(String url) {
        Glide.with(context)
                .load(url)
                .crossFade()
                .into(imageView);
    }


    public void show() {
        if (dialog == null) {
            dialog = builder.create();
        }
        dialog.show();
    }

    public void dismiss() {
        if (dialog != null) {
            dialog.dismiss();
        }
    }


}
